aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/items/[id]/+page.server.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-10 20:39:47 -0700
committerAdam Soltys <[email protected]>2024-09-17 09:18:36 -0700
commit1f63848ca9fb01336f04b41434de1cc06a5b3d93 (patch)
tree2affa3041863be365f33d99e1f32bda60cf93a32 /src/routes/(app)/items/[id]/+page.server.ts
parent6e48c584605bec5623c12c470d04d07303983801 (diff)
downloadcoinos-ui-1f63848ca9fb01336f04b41434de1cc06a5b3d93.tar.gz
coinos-ui-1f63848ca9fb01336f04b41434de1cc06a5b3d93.zip
move routes
Diffstat (limited to 'src/routes/(app)/items/[id]/+page.server.ts')
-rw-r--r--src/routes/(app)/items/[id]/+page.server.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/routes/(app)/items/[id]/+page.server.ts b/src/routes/(app)/items/[id]/+page.server.ts
new file mode 100644
index 00000000..67cebd93
--- /dev/null
+++ b/src/routes/(app)/items/[id]/+page.server.ts
@@ -0,0 +1,21 @@
+import { fd, auth, get, post } from "$lib/utils";
+import { fail, redirect } from "@sveltejs/kit";
+
+export let load = async ({ params: { id } }) => {
+ let item = await get(`/items/${id}`);
+ return { item };
+};
+
+export const actions = {
+ default: async ({ cookies, request, url }) => {
+ let form = await fd(request);
+ try {
+ await post(`/items`, form, auth(cookies));
+ } catch (e: any) {
+ return fail(400, { message: e.message });
+ }
+
+ let success = `/${url.pathname.split("/")[1]}`;
+ redirect(307, success);
+ },
+};